import math
N = 0
def IsPrime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

b = int(input())

if b < 1000 or b > 9999:
    print(0)
else:
    for i in range(3):
        y = b
        if IsPrime(y):
            N = b
            break
        else:
            y = b % 100
            if IsPrime(y) and y > N:
                N = y
            b = b // 10
    
    print(N)
